/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.BoxLayout;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JToggleButton;

public class TitrationGui extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JLabel lblVolumeorconcentration;
	private JLabel lblNewLabel;
	private JTextField textField_2;
	private JLabel lblNewLabel_1;
	private JLabel lblResult;
	private JToggleButton tglbtnConcentration;
	private JTextField textField_3;
	private JTextField textField_4;
	private JLabel lblHOrOh;
	private JLabel lblHOrOh_1;

	/**
	 * Create the frame.
	 */
	public TitrationGui() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		lblVolumeorconcentration = new JLabel("Volume of V1");

		textField = new JTextField();
		lblVolumeorconcentration.setLabelFor(textField);
		textField.setColumns(10);

		textField_1 = new JTextField();
		textField_1.setColumns(10);

		lblNewLabel = new JLabel("Volume of V2");
		lblNewLabel.setLabelFor(textField_1);

		textField_2 = new JTextField();
		textField_2.setColumns(10);

		lblNewLabel_1 = new JLabel("Concentration of C1");
		lblNewLabel_1.setLabelFor(textField_2);

		lblResult = new JLabel("Result");

		JButton btnCalculate = new JButton("Calculate");
		btnCalculate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				float a1 = Float.parseFloat(textField.getText());
				float a2 = Float.parseFloat(textField_1.getText());
				float a3 = Float.parseFloat(textField_2.getText());
				float p1 = Float.parseFloat(textField_3.getText());
				float p2 = Float.parseFloat(textField_4.getText());
				if (tglbtnConcentration.isSelected())
					lblResult.setText(Float
							.toString((a1 * a2 * p1) / (a3 * p2)));
				else
					lblResult.setText(Float
							.toString((a1 * a2 * p1) / (a3 * p2)));

			}
		});

		tglbtnConcentration = new JToggleButton("Concentration");
		tglbtnConcentration.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tglbtnConcentration.isSelected()) {
					tglbtnConcentration.setText("Concentration");
					lblNewLabel.setText("Concentration of C2");
				} else {
					tglbtnConcentration.setText("Volume");
					lblNewLabel.setText("Volume of V2");
				}
			}
		});

		textField_3 = new JTextField();
		textField_3.setText("1");
		textField_3.setColumns(10);

		textField_4 = new JTextField();
		textField_4.setText("1");
		textField_4.setColumns(10);

		lblHOrOh = new JLabel("H or OH ions per mole");
		lblHOrOh.setLabelFor(textField_4);
		lblHOrOh.setToolTipText("Solution 2 protonicity");

		lblHOrOh_1 = new JLabel("H or OH ions per mole Solution 1");
		lblHOrOh_1.setLabelFor(textField_3);
		lblHOrOh_1.setToolTipText("Solution 1 protonicity");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(85)
					.addComponent(btnCalculate, GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
					.addGap(262))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblHOrOh)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField_4, GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addGap(13)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblVolumeorconcentration)
								.addComponent(lblNewLabel_1)
								.addComponent(lblNewLabel))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(textField, GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
								.addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
								.addComponent(textField_2, GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addGap(9)
							.addComponent(lblHOrOh_1, GroupLayout.PREFERRED_SIZE, 147, Short.MAX_VALUE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGap(67)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addComponent(tglbtnConcentration)
							.addGap(39))
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addComponent(lblResult)
							.addGap(86))))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(50)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblVolumeorconcentration)
								.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNewLabel))
							.addGap(12)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblHOrOh_1)
								.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNewLabel_1)))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(33)
							.addComponent(tglbtnConcentration)))
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(18)
							.addComponent(lblResult))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblHOrOh)
								.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addGap(18)
					.addComponent(btnCalculate)
					.addGap(15))
		);
		contentPane.setLayout(gl_contentPane);

	}
}
